package ace.module.sms.core.impl.manager.impl;

import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.spring.AbstractSpringDtoManager;
import ace.cmp.i18n.api.MessageSourceAssertService;
import ace.cmp.spring.data.jdbc.querydsl.core.util.DeleteFlagUtils;
import ace.module.sms.api.enums.SmsApplicationStatusEnum;
import ace.module.sms.api.model.dto.SmsApplicationDto;
import ace.module.sms.core.impl.dao.entity.SmsApplication;
import ace.module.sms.core.impl.manager.SmsApplicationManager;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 短信应用 spring data jdbc querydsl rsql manager implement.
 *
 * @author Caspar
 */
@Slf4j
@AllArgsConstructor
@Component
public class SmsApplicationManagerImpl
    extends AbstractSpringDtoManager<SmsApplication, Long, SmsApplicationDto>
    implements SmsApplicationManager {
  private final MessageSourceAssertService assertService;

  @Override
  public SmsApplication getAndCheckAllById(Long id) {
    SmsApplication smsApplication = this.getById(id);

    assertService.isNull(
        smsApplication, SmsApplication.class.getName() + ".error-not-null", "短信应用不能为空");

    assertService.isTrue(
        DeleteFlagUtils.isDelete(smsApplication),
        SmsApplication.class.getName() + ".error-not-null",
        "短信应用不能为空");

    assertService.isTrue(
        SmsApplicationStatusEnum.LOCKED.getCode().equals(smsApplication.getStatus()),
        SmsApplication.class.getName() + ".error-locked",
        "短信应用已锁定");

    return smsApplication;
  }
}
